<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: rgb(190, 54, 54);
        }
        
        .red {
            background-color: red;
        }
        
        .green {
            background-color: green;
        }
        
        .none {
            display: none;
        }
    </style>
</head>

<body>

    <div class="box "></div>
    <button id="btn"></button>
    <script>
        var btn = document.getElementById("btn");
        var box = document.getElementsByClassName('box')[0];

        btn.innerText = "JS按钮";
        var x = "hah";
        var box_class = box.classList;


        btn.onclick = function() {
            if (box_class.contains('green')) {
                box_class.remove('green');
            } else {
                box_class.add('green');
            };
            if (box_class.contains('none')) {
                box_class.remove('none');
            } else {
                box_class.add('none');
            }
            box.style
        }
    </script>
</body>

</html>